//
//  JXSubjectFrame.m
//  JiaoX
//
//  Created by 尹桥印 on 14/11/12.
//  Copyright (c) 2014年 北京娇羞科技有限公司. All rights reserved.
//

#import "SubjectViewFrame.h"
#import "SubjectItemInfo.h"

@implementation SubjectViewFrame
-(void)setSubject:(SubjectItemInfo *)subject{
    _subject = subject;
    
    
    // 1.专题标题图标
    CGFloat titleIconX = JXPublicInset;
    CGFloat titleIconY = JXPublicInset*2;
    CGFloat titleIconW = 15;
    CGFloat titleIconH = 15;
    self.titleIconFrame = CGRectMake(titleIconX, titleIconY, titleIconW, titleIconH);
    
    // 2.专题标题
    CGFloat titleX = CGRectGetMaxX(self.titleIconFrame) + JXPublicInset;
    CGFloat titleY = titleIconY;
    CGSize titleSize = [subject.subTiltleName sizeWithFont:[UIFont systemFontOfSize:JXSubTitleFont]];
    self.titleFrame = (CGRect){{titleX, titleY}, titleSize};
    
    int topInset = JXPublicInset;
    if([Utils isBlankString:subject.subTiltleName]){
        //将标题与标题图标置为不可见
        self.titleIconFrame = CGRectMake(0, JXPublicInset, 0, 0);
        self.titleFrame = CGRectMake(0, JXPublicInset, 0, 0);
        topInset=0;
    }
    
    // 3.专题图片
    CGFloat subImageX = JXPublicInset;
    CGFloat subImageY = CGRectGetMaxY(self.titleIconFrame)+topInset+JXPublicInset;
    CGFloat subImageW = JXScreenW-2*JXPublicInset;
    CGFloat subImageH = subImageW/2;
    self.subImageFrame = CGRectMake(subImageX, subImageY, subImageW, subImageH);
    
    // 4.专题描述
    CGFloat descLabelX = JXPublicInset;
    CGFloat descLabelY = CGRectGetMaxY(self.subImageFrame)+JXPublicInset;
    CGFloat maxW = JXScreenW - 2 * JXPublicInset;
    CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
    CGSize descSize = [subject.subDesc sizeWithFont:[UIFont systemFontOfSize:JXSubDescFont] constrainedToSize:maxSize];
    self.descLabelFrame = (CGRect){{descLabelX, descLabelY}, descSize};
    
    self.cellHeight = CGRectGetMaxY(self.descLabelFrame)+JXPublicInset;
    
    
    // 自己的frame
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = JXScreenW;
    CGFloat h = self.cellHeight;
    self.frame = CGRectMake(x, y, w, h);
    
}
@end
